package com.example.test_1;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class demoSingieChoice extends AppCompatActivity {

    private String[] sss = new String[]{"小号","大号","中号","特大号"};

    private int[] jjj = new int[]{10,30,20,40};

    private int index;

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_singie_choice);

        textView = findViewById(R.id.user);

    }


    /** setSingleChoiceItems中sss对应上面的下拉文字的数组，chenkedItem是默认选中的位置，最后是点击后的监听事件
     在监听事件当中我们记录他点击的位置，然后进行保存
     然后点击确定按钮时，根据他的位置index，去取出对应的jjj
      */

    public void Dan(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle("请选择字体大小")
                .setSingleChoiceItems(sss, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        index = i;
                    }
                })
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        textView.setTextSize(jjj[index]);
                    }
                })
                .setNegativeButton("取消",null);
        builder.create().show();
    }


}